package com.radar.io.radar346.DataType;

import com.radar.common.GisConstants;
import com.radar.io.radar346.Product382改;
import com.radar.utils.BitConverter;

public class CSParser {
    Product382改 _this;

    public CSParser(Product382改 product382改) {
        _this = product382改;
    }


    public void parse(byte[] bytes, int index, Product382改.RealFile header) throws Exception {
        int Layers = header.realObserSec.iLiTiSaoMiaoCengShu;
        int[] Records = new int[Layers];
        double[] MaxV = new double[Layers];
        int Bins = 0;
        for (int i = 0; i < Layers; i++) {
            Records[i] = header.realObserSec.LayerParam[i].iCaiYangJinXiangShu;
            _this.Bins = header.realObserSec.LayerParam[i].usRefBinNumber;
        }
        _this.azi = new double[Records[0]];  //长度为每层径向数
        float 计算组合切变的仰角度数 = BitConverter.toFloat(bytes, index);   //
        index+=4 ;
        float 计算径向切变的窗口长度 = BitConverter.toFloat(bytes, index);   //
        index += 4 ;
        float 计算方位切变时所选取的窗口大小 = BitConverter.toFloat(bytes, index);
        index += 4 ;
        int  一个径向上所包含的组合切变的个数 = BitConverter.toInt32(bytes, index);
        float 该PPI的最大径向散度 = BitConverter.toFloat(bytes, index);
        index += 4 ;
        float 该PPI的最大组合切变 = BitConverter.toFloat(bytes, index);
        index += 4 ;
        float 最大组合切变所在的方位角 = BitConverter.toFloat(bytes, index);
        index += 4 ;
        float 最大组合切变所在的斜距 = BitConverter.toFloat(bytes, index);
        index += 4 ;

        int m = header.realObserSec.LayerParam[0].usRefBinNumber;
        int n = header.realObserSec.LayerParam[0].iCaiYangJinXiangShu;
        _this.data = new  double[n][m];

        for (int i = 0; i < n; i++) {
            _this.azi[i] = 计算径向切变的窗口长度 * i;
            for (int j = 0; j <m; j++) {
                float v = BitConverter.toFloat(bytes, index);
                _this.data[i][j] = v >= 999 ? GisConstants.UNDEF : (double) v * 1 + 127;
                index += 4 ;
            }
        }
    }
}
